package cc.rengu.igas.momp.biz.service.impl;

import cc.rengu.igas.momp.common.enums.MompTxnNumEnum;
import cc.rengu.igas.momp.common.enums.RespCodeEnum;
import cc.rengu.igas.momp.facade.ManageMchntMcService;
import cc.rengu.igas.momp.facade.request.*;
import cc.rengu.igas.momp.facade.response.*;
import cc.rengu.igas.momp.facade.result.Result;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.DubboResult;
import cc.rengu.oltp.service.realize.DubboService;
import cc.rengu.oltp.service.realize.impl.DubboServiceImpl;

/**
 * 商户侧营销活动管理接口实现
 *
 * @author Jinan Liu
 * @version 1.0.0
 * @date 2020/6/11 15:03
 */
@SuppressWarnings("unchecked")
public class ManageMchntMcServiceImpl implements ManageMchntMcService {

    /**
     * 商户营销活动资金打款Dubbo实现
     *
     * @param mchntMcAccountRechargeRequest 商户营销活动资金打款接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.MchntMcAccountRechargeResponse> 商户营销活动资金打款接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 14:32
     */
    @Override
    public Result<MchntMcAccountRechargeResponse> mchntmcAccountRecharge(MchntMcAccountRechargeRequest mchntMcAccountRechargeRequest) {

        DubboService<MchntMcAccountRechargeRequest> dubboService = new DubboServiceImpl();
        Result<MchntMcAccountRechargeResponse> mchntMcAccountRechargeResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MCHNT_MC_ACCOUNT_RECHARGE.getTxnNum().equals(mchntMcAccountRechargeRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<MchntMcAccountRechargeResponse> dubboResult = dubboService.callAtomService(mchntMcAccountRechargeRequest,
                    MompTxnNumEnum.MCHNT_MC_ACCOUNT_RECHARGE.getService(), MchntMcAccountRechargeResponse.class);
            mchntMcAccountRechargeResponseResult.setResult(dubboResult.getResult());
            mchntMcAccountRechargeResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            MchntMcAccountRechargeResponse mchntMcAccountRechargeResponse = new MchntMcAccountRechargeResponse();
            mchntMcAccountRechargeResponseResult.setResult(mchntMcAccountRechargeResponse);
            mchntMcAccountRechargeResponse.setHeader(mchntMcAccountRechargeRequest.getHeader());
            mchntMcAccountRechargeResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                mchntMcAccountRechargeResponse.setRespCode(((BizException) e).getCode());
                mchntMcAccountRechargeResponse.setRespDesc(e.getMessage());
            } else {
                mchntMcAccountRechargeResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                mchntMcAccountRechargeResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return mchntMcAccountRechargeResponseResult;
    }

    /**
     * 商户查询营销活动详情Dubbo实现
     *
     * @param mchntQueryMcDetailInfoRequest 商户查询营销活动详情接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.MchntQueryMcDetailInfoResponse> 商户查询营销活动详情接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 14:32
     */
    @Override
    public Result<MchntQueryMcDetailInfoResponse> mchntQueryMcDetailInfo(MchntQueryMcDetailInfoRequest mchntQueryMcDetailInfoRequest) {

        DubboService<MchntQueryMcDetailInfoRequest> dubboService = new DubboServiceImpl();
        Result<MchntQueryMcDetailInfoResponse> mchntQueryMcDetailInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MCHNT_QUERY_MC_DETAIL_INFO.getTxnNum().equals(mchntQueryMcDetailInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<MchntQueryMcDetailInfoResponse> dubboResult = dubboService.callAtomService(mchntQueryMcDetailInfoRequest,
                    MompTxnNumEnum.MCHNT_QUERY_MC_DETAIL_INFO.getService(), MchntQueryMcDetailInfoResponse.class);
            mchntQueryMcDetailInfoResponseResult.setResult(dubboResult.getResult());
            mchntQueryMcDetailInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            MchntQueryMcDetailInfoResponse mchntQueryMcDetailInfoResponse = new MchntQueryMcDetailInfoResponse();
            mchntQueryMcDetailInfoResponseResult.setResult(mchntQueryMcDetailInfoResponse);
            mchntQueryMcDetailInfoResponse.setHeader(mchntQueryMcDetailInfoRequest.getHeader());
            mchntQueryMcDetailInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                mchntQueryMcDetailInfoResponse.setRespCode(((BizException) e).getCode());
                mchntQueryMcDetailInfoResponse.setRespDesc(e.getMessage());
            } else {
                mchntQueryMcDetailInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                mchntQueryMcDetailInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return mchntQueryMcDetailInfoResponseResult;
    }

    /**
     * 商户营销活动管理接口Dubbo实现
     *
     * @param mchntMcManageRequest 商户营销活动管理接口请求报文
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.MchntMcManageResponse> 商户营销活动管理接口应答报文
     * @author Jinan Liu
     * @date 2020/6/14 15:37
     */
    @Override
    public Result<MchntMcManageResponse> manageMchntMc(MchntMcManageRequest mchntMcManageRequest) {

        DubboService<MchntMcManageRequest> dubboService = new DubboServiceImpl();
        Result<MchntMcManageResponse> mchntMcManageResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MAMAGE_MCHNT_MC_INFO.getTxnNum().equals(mchntMcManageRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<MchntMcManageResponse> dubboResult = dubboService.callAtomService(mchntMcManageRequest,
                    MompTxnNumEnum.MAMAGE_MCHNT_MC_INFO.getService(), MchntMcManageResponse.class);
            mchntMcManageResponseResult.setResult(dubboResult.getResult());
            mchntMcManageResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            MchntMcManageResponse mchntMcManageResponse = new MchntMcManageResponse();
            mchntMcManageResponseResult.setResult(mchntMcManageResponse);
            mchntMcManageResponse.setHeader(mchntMcManageRequest.getHeader());
            mchntMcManageResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                mchntMcManageResponse.setRespCode(((BizException) e).getCode());
                mchntMcManageResponse.setRespDesc(e.getMessage());
            } else {
                mchntMcManageResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                mchntMcManageResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return mchntMcManageResponseResult;
    }

    /**
     * 商户营销活动发布接口Dubbo实现
     *
     * @param mchntMcPublishRequest 商户营销活动发布接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.MchntMcPublishResponse> 商户营销活动发布接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 15:38
     */
    @Override
    public Result<MchntMcPublishResponse> publishMchntMc(MchntMcPublishRequest mchntMcPublishRequest) {

        DubboService<MchntMcPublishRequest> dubboService = new DubboServiceImpl();
        Result<MchntMcPublishResponse> mchntMcPublishResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MCHNT_MC_PUBLISH.getTxnNum().equals(mchntMcPublishRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<MchntMcPublishResponse> dubboResult = dubboService.callAtomService(mchntMcPublishRequest,
                    MompTxnNumEnum.MCHNT_MC_PUBLISH.getService(), MchntMcPublishResponse.class);
            mchntMcPublishResponseResult.setResult(dubboResult.getResult());
            mchntMcPublishResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            MchntMcPublishResponse mchntMcPublishResponse = new MchntMcPublishResponse();
            mchntMcPublishResponseResult.setResult(mchntMcPublishResponse);
            mchntMcPublishResponse.setHeader(mchntMcPublishRequest.getHeader());
            mchntMcPublishResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                mchntMcPublishResponse.setRespCode(((BizException) e).getCode());
                mchntMcPublishResponse.setRespDesc(e.getMessage());
            } else {
                mchntMcPublishResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                mchntMcPublishResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return mchntMcPublishResponseResult;
    }


    /**
     * 商户参与联合营销活动Dubbo实现
     *
     * @param mchntJoinJointMcRequest 商户参与联和营销活动接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.MchntJoinJointMcResponse> 商户参与联和营销活动接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 14:31
     */
    @Override
    public Result<MchntJoinJointMcResponse> mchntJoinJointMc(MchntJoinJointMcRequest mchntJoinJointMcRequest) {

        DubboService<MchntJoinJointMcRequest> dubboService = new DubboServiceImpl();
        Result<MchntJoinJointMcResponse> mchntJoinJointMcResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MCHNT_JOIN_JOINT_MC.getTxnNum().equals(mchntJoinJointMcRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<MchntJoinJointMcResponse> dubboResult = dubboService.callAtomService(mchntJoinJointMcRequest,
                    MompTxnNumEnum.MCHNT_JOIN_JOINT_MC.getService(), MchntJoinJointMcResponse.class);
            mchntJoinJointMcResponseResult.setResult(dubboResult.getResult());
            mchntJoinJointMcResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            MchntJoinJointMcResponse mchntJoinJointMcResponse = new MchntJoinJointMcResponse();
            mchntJoinJointMcResponseResult.setResult(mchntJoinJointMcResponse);
            mchntJoinJointMcResponse.setHeader(mchntJoinJointMcRequest.getHeader());
            mchntJoinJointMcResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                mchntJoinJointMcResponse.setRespCode(((BizException) e).getCode());
                mchntJoinJointMcResponse.setRespDesc(e.getMessage());
            } else {
                mchntJoinJointMcResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                mchntJoinJointMcResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return mchntJoinJointMcResponseResult;
    }

    /**
     * 收银员收款账号配置接口Dubbo实现
     *
     * @param manageCashierAccountRequest 收银员收款账号配置接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.ManageCashierAccountResponse> 收银员收款账号配置接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 15:46
     */
    @Override
    public Result<ManageCashierAccountResponse> manageCashierAccount(ManageCashierAccountRequest manageCashierAccountRequest) {

        DubboService<ManageCashierAccountRequest> dubboService = new DubboServiceImpl();
        Result<ManageCashierAccountResponse> manageCashierAccountResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MANAGE_CASHIER_ACCOUNT.getTxnNum().equals(manageCashierAccountRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<ManageCashierAccountResponse> dubboResult = dubboService.callAtomService(manageCashierAccountRequest,
                    MompTxnNumEnum.MANAGE_CASHIER_ACCOUNT.getService(), ManageCashierAccountResponse.class);
            manageCashierAccountResponseResult.setResult(dubboResult.getResult());
            manageCashierAccountResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            ManageCashierAccountResponse manageCashierAccountResponse = new ManageCashierAccountResponse();
            manageCashierAccountResponse.setHeader(manageCashierAccountRequest.getHeader());
            manageCashierAccountResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                manageCashierAccountResponse.setRespCode(((BizException) e).getCode());
                manageCashierAccountResponse.setRespDesc(e.getMessage());
            } else {
                manageCashierAccountResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                manageCashierAccountResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return manageCashierAccountResponseResult;
    }

    /**
     * 收银员信息查询接口Dubbo实现
     *
     * @param queryCashierInfoRequest 收银员信息查询接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryCashierInfoResponse> 收银员信息查询接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 16:00
     */
    @Override
    public Result<QueryCashierInfoResponse> queryCashierInfo(QueryCashierInfoRequest queryCashierInfoRequest) {

        DubboService<QueryCashierInfoRequest> dubboService = new DubboServiceImpl();
        Result<QueryCashierInfoResponse> queryCashierInfoResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.MANAGE_CASHIER_ACCOUNT.getTxnNum().equals(queryCashierInfoRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<QueryCashierInfoResponse> dubboResult = dubboService.callAtomService(queryCashierInfoRequest,
                    MompTxnNumEnum.MANAGE_CASHIER_ACCOUNT.getService(), QueryCashierInfoResponse.class);
            queryCashierInfoResponseResult.setResult(dubboResult.getResult());
            queryCashierInfoResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            QueryCashierInfoResponse queryCashierInfoResponse = new QueryCashierInfoResponse();
            queryCashierInfoResponseResult.setResult(queryCashierInfoResponse);
            queryCashierInfoResponse.setHeader(queryCashierInfoRequest.getHeader());
            queryCashierInfoResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                queryCashierInfoResponse.setRespCode(((BizException) e).getCode());
                queryCashierInfoResponse.setRespDesc(e.getMessage());
            } else {
                queryCashierInfoResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                queryCashierInfoResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return queryCashierInfoResponseResult;
    }

    /**
     * 收银员参与收银员返现活动Dubbo实现
     *
     * @param cashierJoinCashierCashbackRequest 收银员参与收银员返现活动接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.CashierJoinCashierCashbackResponse> 收银员参与收银员返现活动接口应答对象
     * @author Jinan Liu
     * @date 2020/6/14 14:33
     */
    @Override
    public Result<CashierJoinCashierCashBackResponse> cashierJoinCashierCashback(CashierJoinCashierCashBackRequest cashierJoinCashierCashbackRequest) {

        DubboService<CashierJoinCashierCashBackRequest> dubboService = new DubboServiceImpl();
        Result<CashierJoinCashierCashBackResponse> cashierJoinCashierCashbackResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.CASHIER_JOIN_CASHIER_CASHBACK_MC.getTxnNum().equals(cashierJoinCashierCashbackRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<CashierJoinCashierCashBackResponse> dubboResult = dubboService.callAtomService(cashierJoinCashierCashbackRequest,
                    MompTxnNumEnum.CASHIER_JOIN_CASHIER_CASHBACK_MC.getService(), CashierJoinCashierCashBackResponse.class);
            cashierJoinCashierCashbackResponseResult.setResult(dubboResult.getResult());
            cashierJoinCashierCashbackResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            CashierJoinCashierCashBackResponse cashierJoinCashierCashbackResponse = new CashierJoinCashierCashBackResponse();
            cashierJoinCashierCashbackResponseResult.setResult(cashierJoinCashierCashbackResponse);
            cashierJoinCashierCashbackResponse.setHeader(cashierJoinCashierCashbackRequest.getHeader());
            cashierJoinCashierCashbackResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                cashierJoinCashierCashbackResponse.setRespCode(((BizException) e).getCode());
                cashierJoinCashierCashbackResponse.setRespDesc(e.getMessage());
            } else {
                cashierJoinCashierCashbackResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                cashierJoinCashierCashbackResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return cashierJoinCashierCashbackResponseResult;
    }

    /**
     * 收银员返现明细查询接口
     * * 收银员使用
     *
     * @param cashierMcCashbackDetailRequest 收银员返现活动明细列表查询接口请求对象
     * @return cc.rengu.igas.momp.facade.result.Result<cc.rengu.igas.momp.facade.response.QueryCashbackToCashierDetailResponse> 收银员返现活动明细列表查询接口应答对象
     * @author Jinan Liu
     * @date 2020/5/22 11:02
     */
    @Override
    public Result<CashierMcCashbackDetailResponse> queryCashierCashbackDetail(CashierMcCashbackDetailRequest cashierMcCashbackDetailRequest) {

        DubboService<CashierMcCashbackDetailRequest> dubboService = new DubboServiceImpl();
        Result<CashierMcCashbackDetailResponse> cashierMcCashbackDetailResponseResult = new Result<>();
        try {
            if (!MompTxnNumEnum.QUERY_CASHIER_CASHBACK_DETAIL.getTxnNum().equals(cashierMcCashbackDetailRequest.getHeader().getTxnNum())) {
                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
            }
            // 通过服务名调用相应的服务
            DubboResult<CashierMcCashbackDetailResponse> dubboResult = dubboService.callAtomService(cashierMcCashbackDetailRequest,
                    MompTxnNumEnum.QUERY_CASHIER_CASHBACK_DETAIL.getService(), CashierMcCashbackDetailResponse.class);
            cashierMcCashbackDetailResponseResult.setResult(dubboResult.getResult());
            cashierMcCashbackDetailResponseResult.setSuccess(dubboResult.isSuccess());

        } catch (Exception e) {

            CashierMcCashbackDetailResponse cashierMcCashbackDetailResponse = new CashierMcCashbackDetailResponse();
            cashierMcCashbackDetailResponseResult.setResult(cashierMcCashbackDetailResponse);
            cashierMcCashbackDetailResponse.setHeader(cashierMcCashbackDetailRequest.getHeader());
            cashierMcCashbackDetailResponseResult.setSuccess(false);
            if (e instanceof BizException) {
                cashierMcCashbackDetailResponse.setRespCode(((BizException) e).getCode());
                cashierMcCashbackDetailResponse.setRespDesc(e.getMessage());
            } else {
                cashierMcCashbackDetailResponse.setRespCode(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                cashierMcCashbackDetailResponse.setRespDesc(OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
            }
        }


        return cashierMcCashbackDetailResponseResult;
    }
}
